<template>
	<view class="page">
		<view class="list-box">
			<view 
			class="item-box" 
			hover-class="hover"
			v-for="(item,index) in listData" 
			:key="item.id" 
			@tap="goDetail(item.id)">
				<image class="item-box_cover" :src="item.scene_pic_url" ></image>
				<view class="item-box_title">{{item.title}}</view>
			</view>
		</view>
		<uni-load-more :status="loadStatus" :showText="pageParams.isLoadEnd && listData.length > 1"></uni-load-more>
	</view>
</template>

<script>
	import {getSeedingListApi} from '@/api/seeding.js'
	export default {
		data() {
			return {
				loadStatus: 'more',
				pageParams: {
					page: 1,
					isLoadEnd: false
				},
				listData: []
			}
		},
		onLoad() {
			uni.hideTabBar()
			this.getListData()
		},
		onPullDownRefresh() {
			this.pageParams.page = 1
			this.pageParams.isLoadEnd = false
			this.getListData()
		},
		onReachBottom() {
			if(this.pageParams.isLoadEnd) return
			this.pageParams.page++
			this.getListData()
		},
		methods: {
			goDetail(id) {
				uni.navigateTo({
					url: `/pages/aPackage/articleDetail/articleDetail?id=${id}`
				})
			},
			async getListData() {
				this.loadStatus = 'loading'
				const res = await getSeedingListApi({
					page: this.pageParams.page
				})
				uni.stopPullDownRefresh()
				this.loadStatus = 'more'
				if(this.pageParams.page < 10) {
					this.pageParams.isLoadEnd = true
					this.loadStatus = 'no-more'
				}
				if(this.pageParams.page === 1) {
					this.listData = res.data.data
				}else {
					this.listData = this.listData.concat(res.data.data)
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		padding-top: 20rpx;
		padding-bottom: 60rpx;
		min-height: 100vh;
		background-color: #f5f5f5;
		box-sizing: border-box;
	}
	.list-box {
		padding-left: 30rpx;
		padding-right: 30rpx;
		box-sizing: border-box;
	}
	.item-box {
		box-shadow: 2rpx 8rpx 4rpx 2rpx rgba(0, 0, 0, .15);
		border-radius: 40rpx;
		overflow: hidden;
		background-color: #ffffff;
		margin-bottom: 30rpx;
		&_cover {
			width: 100%;
			height: 300rpx;
		}
		&_title {
			font-size: 32rpx;
			color: #333333;
			text-align: center;
			padding: 20rpx;
			box-sizing: border-box;
			line-height: 48rpx;
		}
	}
</style>